
* program to store results in a matrix - RD
cap prog drop stores
prog def stores
	args z /* z = estimation number */
	* estimates
	matrix r`z'[1,1] = e(tau_bc)
	matrix r`z'[1,2] = e(se_tau_rb)
	matrix r`z'[1,3] = e(pv_rb)
	* observations and bandwidths
	matrix s[1,`z'] = e(h_l)
	matrix s[2,`z'] = e(N_h_l)+e(N_h_r)
end

* program to combine RD results into a table
cap prog drop cmb_tbl
prog def cmb_tbl
	args n /* number of matrices to combine */
	forval i = 1/`n' {
		frmttable, statmat(r`i') substat(2) sdec(3) ///
			rtitles("RD estimate" \ "St. error" \ "\$p$-value") ///
			merge
		}
	frmttable, statmat(s) sdec(3\0) append rtitles("Bandwidth" \ "N")
end

* program to combine RD results for balance tests
cap prog drop storeb
prog def storeb
	args z /* z = estimation number */
	matrix b`z'[1,1] = e(tau_bc)
	matrix b`z'[1,2] = e(se_tau_rb)
	matrix b`z'[1,3] = e(pv_rb)
	matrix b`z'[1,4] = e(h_l)
	matrix b`z'[1,5] = e(N_h_l)+e(N_h_r)
end

* program to store results in a matrix - FE
cap prog drop storesfe
prog def storesfe
	args z v /* z = estimation number
				v = variable name */
	* estimates
	matrix r`z'[1,1] = _b[`v']
	matrix r`z'[1,2] = _se[`v']
	matrix r`z'[1,3] = (1-normal(abs(_b[`v']/_se[`v'])))*2
	* observations
	matrix s[1,`z'] = e(N)
end

* program to combine FE results into a table
cap prog drop cmb_tbl_fe
prog def cmb_tbl_fe
	args n /* number of matrices to combine */
	forval i = 1/`n' {
		frmttable, statmat(r`i') substat(2) sdec(3) ///
			rtitles("FE estimate" \ "St. error" \ "\$p$-value") ///
			merge
		}
	frmttable, statmat(s) sdec(0) append rtitles("N")
end